package com.fengmi.goods.service.impl;

import com.fengmi.goods.entity.MallGoodsSku;
import com.fengmi.goods.mapper.MallGoodsSkuMapper;
import com.fengmi.goods.service.IMallGoodsSkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fengmi.vo.ResultVO;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author zhuxm
 * @since 2022-03-02
 */
@Service
public class MallGoodsSkuServiceImpl extends ServiceImpl<MallGoodsSkuMapper, MallGoodsSku> implements IMallGoodsSkuService {

    @Override
    public ResultVO kcc(String skuId, Integer buyNum) {
        MallGoodsSku sku = this.baseMapper.selectById(skuId);
        if (sku == null) {
            return  new ResultVO(false,"商品不存在");
        }

        if(sku.getSkuStock() < buyNum){

            return  new ResultVO(false,"库存不足");
        }

        sku.setSkuStock(sku.getSkuStock() - buyNum);

        this.baseMapper.updateById(sku);


        return new ResultVO(true,"success");
    }
}
